<?php
//测试数据下载类
class DAction extends Action {
	private  $url='http://www.mumayi.com';
	private $cat_id=19;
	
	function index(){
		for ($i=1; $i <= 20; $i++){
			$url[] = "http://www.mumayi.com/android/yangchengyouxi/list_65_{$i}.html";
		}
		foreach ($url as $u){
			//$this->getContent($u);
		}
		echo 'ok';
	}
	
	function getIcons($content){
		
	}
	
	function getContent($url){
		$content = file_get_contents($url);
		$array=array();
		preg_match("#<div class=\"list_main_center\">(.*)<div class=\"list_main_footer\">#isU", $content, $array);
		$content = isset($array[0])?$array[0]:'';
		if(!$content) return false;
		$images = array();
		preg_match_all("/\<img src='([\/\-\._0-9a-zA-Z]+)' border='0'/", $content, $images);
		$images = isset($images[1])?$images[1]:array();
		$titles = array();
		preg_match_all("/alt='(.*)'\>/isU", $content, $titles);
		$titles = isset($titles[1])?$titles[1]:array();
		$decs = array();
		preg_match_all("/html\">(.*)\<\/a\>/isU", $content, $decs);
		$decs = isset($decs[1])?$decs[1]:array();
		$short_desc = array();
		preg_match_all("/\<h3 class=\"editorcontent\"\>(.*)\<\/h3\>/isU", $content, $short_desc);
		$short_desc = isset($short_desc[1])?$short_desc[1]:array();
		$target_id = array();
		preg_match_all("/\/disdls.php\?aid=([0-9]+)\"/", $content, $target_id);
		$target_id = isset($target_id[1])?$target_id[1]:array();
		//入库
		if(count($short_desc)==10 && count($images)==10 && count($titles)==10 && count($decs)==10){
			foreach ($images as $key=>$image){
				$data['title'] = $titles[$key];
				$data['icon_url'] = $this->url.$image;
				$data['short_desc'] = $short_desc[$key];
				$data['berif'] = $decs[$key];
				$data['cat_id'] = $this->cat_id;
				$data['target_id'] = $target_id[$key];
				$row = M('Temp')->where('target_id='.$target_id[$key])->find();
				if($row) continue;
				M('Temp')->add($data);
			}
		}
		return TRUE;
	}
}
?>